$().ready(function() {
	validateRule();
});

$.validator.setDefaults({
	submitHandler : function() {
		save();
	}
});
function save() {
	$.ajax({
		cache : true,
		type : "POST",
		url : "/jzweb/examinationRoom/save",
		data : $('#signupForm').serialize(),// 你的formid
		async : false,
		error : function(request) {
			parent.layer.alert("Connection error");
		},
		success : function(data) {
			if (data.code == 0) {
				parent.layer.msg("操作成功");
				parent.reLoad();
				var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
				parent.layer.close(index);

			} else {
				parent.layer.alert(data.msg)
			}

		}
	});

}
function validateRule() {
	var icon = "<i class='fa fa-times-circle'></i> ";
	$("#signupForm").validate({
		rules : {
			name : {
				required : true
			},
            orgId : {
                required : true
            },
            profileId : {
                required : true
            },
            type : {
                required : true
            },
            seatSize : {
                required : true
            },
            campus : {
                required : true
            },
            storiedBuilding : {
                required : true
            },
            houseNumber : {
                required : true
            }
		},
		messages : {
			name : {
				required : icon + "请输入考场名称"
			},
            orgId : {
                required : icon + "请选择机构"
            },
            profileId : {
                required : icon + "请选择证书"
            },
            type : {
                required : icon + "请选择考场类型"
            },
            seatSize : {
                required : icon + "请输入座位数量"
            },
            campus : {
                required : icon + "请输入校区"
            },
            storiedBuilding : {
                required : icon + "请输入楼栋"
            },
            houseNumber : {
                required : icon + "请输入门牌号"
            }
		}
	})
}
layui.use('upload', function () {
    var upload = layui.upload;
    upload.render({
        elem: '#btnUpload', //绑定元素
        url: '/common/sysFile/upload', //上传接口
        accept: 'file',
        done: function (r) {
            $("#proofMaterial").val(r.data);
            $("#test").html(subFileName(r.data));
        },
        error: function (r) {
            layer.msg(r.msg);
        }
    });
});